<?php

class Album_model extends MY_Model {
	
	public $table = 'album';
	
	function __construct() {
		parent::__construct();
	}
	
	function addOne($data) {
		return $this->insert($data);
	}
	
	function deleteAll($ids) {
		$id = trim($ids, ',');
		$ids = explode(',', $id);		
		return $this->delete(array('id'=>$ids));
	}
	
	function getAll($ids, $field='') {
		if(is_string($ids)) {
			$id = trim($ids, ',');
			$ids = explode(',', $id);
		}
		
		$this->db->where_in('id', $ids);
		if(!empty($field)) {
			$this->db->select($field);
		}
		$query = $this->db->get($this->table);
		return $query->result_array();
	}
	
	function add($data) {
		$this->db->trans_start();
		$this->db->insert_batch ( $this->table, $data );
		$this->db->trans_complete();
		return $this->db->trans_status();
	}
	/**
	 * 取得所有广告图
	 * 
	 * @param array $config
	 * @param array $like
	 * @return array
	 */
	public function getBannerAll($config = array(), $like = array()) {
		$where=array('from'=> '3','type'=>'2');
		$config['totalCount'] = $this->get_search_num($where, $like);
		if($config['offset'] >= $config['totalCount']) {
			$config['offset'] = 0;
			$config['pageNum'] = 1;
 		}
		$config['data'] = $this->search($where, $config, $like);
		return $config;
	}
}